package com.uikoo9.manage.y.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import com.uikoo9.manage.y.util.SqlKit;
import com.uikoo9.plugin.QLogger1;
import com.uikoo9.util.core.annotation.QTable;
import com.uikoo9.util.core.data.QStringUtil;

/**
 * YProjectModel<br>
 * id	id<br>
 * y_project_name	名称<br>
 * cdate	创建时间<br>
 * cuser_id	input_id<br>
 * cuser_name	input_name<br>
 * y_project_sort	排序<br>
 * y_project_type	类型1日常2工作3兴趣4其他<br>
 * @author qiaowenbin
 */
@QTable("t_y_project")
@SuppressWarnings("serial")
public class YProjectModel extends Model<YProjectModel>{
	
	public static final YProjectModel dao = new YProjectModel();
	
	/**
	 * find all
	 * @return
	 */
	public List<YProjectModel> findAll(){
		return findAll(null);
	}
	
	/**
	 * find all by order
	 * @param order
	 * @return
	 */
	public List<YProjectModel> findAll(String order){
		StringBuilder sb = new StringBuilder("");
        SqlKit s = new SqlKit();
        sb.append(s.appendRightSql("select * from t_y_project where 1=1 ","","")) ;
		if(QStringUtil.isEmpty(order)){
			return dao.find(sb.append("order by id desc").toString());
		}else{
			return dao.find(sb.append(order).toString());
		}
	}

	/**
	 *
	 * @param querytype  可以为空 默认为 =，其他 in like 等需要设置
	 * @param param 查询参数
	 * @return
	 */
	public List<Record> findMyProject(Map<String,Object[]> querytype,Map<String,Object> param){
		String sql = "select c.y_team_name,b.y_team_id,a.y_project_name as text,a.* from t_y_project a\n" +
				"LEFT JOIN t_y_teamruser b on a.cuser_id = b.ucenter_user_id and b.y_team_user_type = 2\n" +
				"LEFT JOIN t_y_team c on b.y_team_id = c.id where 1=1 ";

		SqlKit s = new SqlKit();
		if(param!=null && !param.isEmpty()){
			if(querytype != null){
				s.buildSQL(querytype,param);
			}else {
				s.buildSQL(param);
			}
			sql+= s.getSql();
		}
		sql = sql+"order by y_project_sort ";
		QLogger1.getLogger().debug(sql);

		List<Record> list = Db.find(sql,s.getParamArray());
		return list;
	}
	
}
